package com.coder520.sync_learning.demo;

import java.lang.Exception;
import java.lang.Override;
import java.lang.Runnable;
import java.lang.String;
import java.lang.Thread;

public class ThreadState {
	public static void main(String[] args) {
		new Thread(new TimeWaiting(),"timewaitingThread").start();
		new Thread(new Waiting(),"waitingThread").start();
//		使用两个Block线程，一个获取锁成功，另一个则被阻塞
		new Thread(new Blocked(),"BlockThread-1").start();
		new Thread(new Blocked(),"BlockThread-2").start();
		
		
	}
	
	static class TimeWaiting implements Runnable{

		@Override
		public void run() {
			// TODO Auto-generated method stub
			while (true) {
				SleepUtils.second(100);
			}
		}
		
	}
	
	
	static class Waiting implements Runnable{

		@Override
		public void run() {
			// TODO Auto-generated method stub
			while (true) {
				synchronized (Waiting.class) {
					try {
						Waiting.class.wait();
					} catch (Exception e) {
						// TODO: handle exception
						e.printStackTrace();
					}
				}
			}
		}
	}
	
	static class Blocked implements Runnable{

		@Override
		public void run() {
			// TODO Auto-generated method stub
			synchronized (Blocked.class) {
				while(true) {
					SleepUtils.second(100);
				}
			}
		}
	}
	
}
